home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / private / pdcscrn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  7.7 KB  |  245 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21. #ifdef UNIX
  22. #include <defs.h>
  23. #include <term.h>
  24. #undef lines
  25. #endif
  26.  
  27. #ifdef PDCDEBUG
  28. char *rcsid_PDCscrn  = "$Id$";
  29. #endif
  30.  
  31. /*man-start*********************************************************************
  32.  
  33.   PDC_scr_close()    - Internal low-level binding to close the physical screen
  34.  
  35.   PDCurses Description:
  36.      This function provides a low-level binding for the Flexos
  37.      platform which must close the screen before writing to it.
  38.      This is a nop for the DOS platform.
  39.  
  40.      This function is provided in order to reset the FlexOS 16 bit
  41.      character set for input rather than the limited input
  42.      character set associated with the VT52.
  43.  
  44.   PDCurses Return Value:
  45.      This function returns OK on success, otherwise an ERR is returned.
  46.  
  47.   PDCurses Errors:
  48.      The DOS platform will never fail.  The Flexos platform may fail
  49.      depending on the ability to close the current virtual console in
  50.      8 (as opposed to 16) bit mode.
  51.  
  52.   Portability:
  53.      PDCurses    int    PDC_scr_close( void );
  54.  
  55. **man-end**********************************************************************/
  56.  
  57. int    PDC_scr_close(void)
  58. {
  59. #ifdef PDCDEBUG
  60.     if (trace_on) PDC_debug("PDC_scr_close() - called\n");
  61. #endif
  62.  
  63. #ifdef    FLEXOS
  64.     _flexos_8bitmode();
  65.     vir.vc_kbmode = kbmode;
  66.     vir.vc_smode = smode;
  67.     vir.vc_mode = cmode;
  68.     retcode = s_set(T_VIRCON, 1L, (char *) &vir, (long) sizeof(vir));
  69.     if  (retcode < 0L)
  70.         return( ERR );
  71.     return( OK );
  72. #endif
  73.  
  74.     return( OK );
  75. }
  76.  
  77. /*man-start*********************************************************************
  78.  
  79.   PDC_scrn_modes_equal()    - Decide if two screen modes are equal
  80.  
  81.   PDCurses Description:
  82.      Mainly required for OS/2. It decides if two screen modes
  83.         (VIOMODEINFO structure) are equal. Under DOS it just compares
  84.         two integers
  85.  
  86.   PDCurses Return Value:
  87.      This function returns TRUE if equal else FALSe.
  88.  
  89.   PDCurses Errors:
  90.      No errors are defined for this function.
  91.  
  92.   Portability:
  93.      PDCurses    int PDC_scrn_modes_equal( int mode1, int mode2 );
  94.      OS2 PDCurses    int PDC_scrn_modes_equal( VIOMODEINFO mode1, VIOMODEINFO mode2 );
  95.  
  96. **man-end**********************************************************************/
  97.  
  98. #if defined( OS2 ) && !defined( EMXVIDEO )
  99. bool    PDC_scrn_modes_equal(VIOMODEINFO mode1, VIOMODEINFO mode2)
  100. #else
  101. bool    PDC_scrn_modes_equal(int mode1, int mode2)
  102. #endif
  103. {
  104. #ifdef PDCDEBUG
  105.     if (trace_on) PDC_debug("PDC_scrn_modes_equal() - called\n");
  106. #endif
  107.  
  108. #if defined( OS2 ) && !defined( EMXVIDEO )
  109.     return (   (mode1.cb == mode2.cb) && (mode1.fbType == mode2.fbType)
  110.             && (mode1.color == mode2.color) && (mode1.col == mode2.col)
  111.             && (mode1.row == mode2.row) && (mode1.hres == mode2.vres)
  112.             && (mode1.vres == mode2.vres) );
  113. #else
  114.     return (mode1 == mode2);
  115. #endif
  116. }
  117.  
  118. /*man-start*********************************************************************
  119.  
  120.   PDC_scr_open()    - Internal low-level binding to open the physical screen
  121.  
  122.   PDCurses Description:
  123.      This function provides a low-level binding for the Flexos
  124.      platform which must open the screen before writing to it.
  125.  
  126.      This function is provided in order to access the FlexOS 16 bit
  127.      character set for input rather than the limited input
  128.      character set associated with the VT52.
  129.  
  130.   PDCurses Return Value:
  131.      This function returns OK on success, otherwise an ERR is returned.
  132.  
  133.   PDCurses Errors:
  134.      The DOS platform will never fail.  The Flexos platform may fail
  135.      depending on the ability to open the current virtual console in
  136.      8 (as opposed to 16) bit mode.
  137.  
  138.   Portability:
  139.      PDCurses    int    PDC_scr_open( SCREEN* internal, bool echo );
  140.  
  141. **man-end**********************************************************************/
  142.  
  143. int    PDC_scr_open(SCREEN *internal, bool echo)
  144. {
  145.  
  146. #ifdef PDCDEBUG
  147.     if (trace_on) PDC_debug("PDC_scr_open() - called\n");
  148. #endif
  149.  
  150. #ifdef    FLEXOS
  151.     retcode = s_get(T_VIRCON, 0L, (char *) &vir, (long) sizeof(vir));
  152.     if (retcode < 0L)
  153.         return( ERR );
  154.  
  155.     kbmode = vir.vc_kbmode;
  156.     cmode = vir.vc_mode;
  157.     vir.vc_mode = 0;
  158.  
  159.     if (!echo)    vir.vc_kbmode |= VCKM_NECHO;
  160.     else        vir.vc_kbmode &= ~VCKM_NECHO;
  161.  
  162.     smode = vir.vc_smode;
  163.     retcode = s_set(T_VIRCON, 0L, (char *) &vir, (long) sizeof(vir));
  164.     if  (retcode < 0L)
  165.         return( ERR );
  166.  
  167.     if (vir.vc_type & 0x03)    internal->mono = TRUE;
  168.     else            internal->mono = FALSE;
  169.  
  170.     internal->orig_attr = vir.vc_flcolor | vir.vc_blcolor;
  171.     _flexos_16bitmode();
  172. #endif
  173.  
  174. #ifdef    DOS
  175.     internal->orig_attr     = 0;
  176.     internal->orig_emulation = getdosmembyte (0x487);
  177. #endif
  178.  
  179. #ifdef    OS2
  180.     internal->orig_attr     = 0;
  181.     internal->orig_emulation = 0;
  182. #endif
  183.  
  184. #ifdef UNIX
  185.     PDC_get_cursor_pos(&internal->cursrow, &internal->curscol);
  186.     internal->autocr    = FALSE;        /* lf -> crlf by default      */
  187.     internal->raw_out    = FALSE;    /* tty I/O modes          */
  188.     internal->raw_inp    = FALSE;    /* tty I/O modes          */
  189.     internal->cbreak    = FALSE;
  190.     internal->echo        = echo;
  191.     internal->refrbrk    = FALSE;    /* no premature end of refresh*/
  192.     internal->visible_cursor= TRUE;        /* Assume that it is visible  */
  193.     internal->cursor    = 0;
  194.     internal->font        = 0;
  195.     internal->lines        = PDC_get_rows();
  196.     internal->cols        = PDC_get_columns();
  197.     internal->audible    = TRUE;
  198.     internal->direct_video    = FALSE;        /* Assume that we can          */
  199.     internal->adapter    = PDC_query_adapter_type();
  200.     _CUR_TERM.prog_mode.c_iflag &= ~(ICRNL);
  201.     _CUR_TERM.prog_mode.c_oflag &= ~(ONLCR|OPOST);
  202.     _CUR_TERM.prog_mode.c_lflag &= ~(ICANON|ECHO);
  203.     _CUR_TERM.prog_mode.c_cc[VMIN] = 1;
  204.     ioctl(_CUR_TERM.fd, TCSETA, &_CUR_TERM.prog_mode);
  205.     return(OK);
  206. #endif
  207.  
  208. #if defined(XCURSES)
  209.     internal->cursrow = internal->curscol = 0;
  210.     internal->direct_video    = FALSE;        /* Assume that we can't          */
  211. #else
  212.     PDC_get_cursor_pos(&internal->cursrow, &internal->curscol);
  213.     internal->direct_video    = TRUE;        /* Assume that we can          */
  214. #endif
  215.  
  216.     internal->autocr    = TRUE;        /* lf -> crlf by default      */
  217.     internal->raw_out    = FALSE;    /* tty I/O modes          */
  218.     internal->raw_inp    = FALSE;    /* tty I/O modes          */
  219.     internal->cbreak    = TRUE;
  220.     internal->echo        = echo;
  221. /* under System V Curses, typeahead checking is enabled by default */
  222.     internal->refrbrk    = TRUE;    /* allow premature end of refresh*/
  223. #if !defined(OS2) && !defined(XCURSES)
  224.     internal->video_seg    = 0xb000;    /* Base screen segment addr   */
  225.     internal->video_ofs    = 0x0;        /* Base screen segment ofs    */
  226. #endif
  227.     internal->video_page    = 0;        /* Current Video Page          */
  228.     internal->visible_cursor= TRUE;        /* Assume that it is visible  */
  229.     internal->cursor    = PDC_get_cursor_mode();
  230. #ifdef EMXVIDEO
  231.     internal->tahead    = -1;
  232. #endif
  233.     internal->adapter    = PDC_query_adapter_type();
  234.     internal->font        = PDC_get_font();
  235. #if !defined(EMXVIDEO) && !defined(XCURSES)
  236.     internal->scrnmode    = PDC_get_scrn_mode();
  237. #endif
  238.     internal->lines        = PDC_get_rows();
  239.     internal->cols        = PDC_get_columns();
  240.     internal->audible    = TRUE;
  241.     internal->visibility    = 1;
  242.     return( OK );
  243. }
  244.